﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using TyMES.Model.BaseInformation;
using TyMES.Model;

namespace TyMES.ViewModel.BaseInformation.WorkshopVMs
{
    public partial class WorkshopListVM : BasePagedListVM<Workshop_View, WorkshopSearcher>
    {
        
        protected override IEnumerable<IGridColumn<Workshop_View>> InitGridHeader()
        {
            return new List<GridColumn<Workshop_View>>{
                
                this.MakeGridHeader(x => x.Workshop_FactoryCode_FactoryCode).SetTitle(@Localizer["Page.工厂编码"].Value),
                this.MakeGridHeader(x => x.Workshop_WorkshopCode).SetTitle(@Localizer["Page.车间编码"].Value),
                this.MakeGridHeader(x => x.Workshop_WorkshopName).SetTitle(@Localizer["Page.车间名称"].Value),
                this.MakeGridHeader(x => x.Workshop_ResponsibleId).SetTitle(@Localizer["Page.负责人"].Value),
                this.MakeGridHeader(x => x.Workshop_Status).SetTitle(@Localizer["Page.车间状态"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<Workshop_View> GetSearchQuery()
        {
            var query = DC.Set<Workshop>()
                
                .CheckEqual(Searcher.FactoryCodeId, x=>x.FactoryCodeId)
                .CheckContain(Searcher.WorkshopCode, x=>x.WorkshopCode)
                .CheckContain(Searcher.WorkshopName, x=>x.WorkshopName)
                .CheckContain(Searcher.ResponsibleId, x=>x.ResponsibleId)
                .CheckEqual(Searcher.Status, x=>x.Status)
                .Select(x => new Workshop_View
                {
				    ID = x.ID,
                    
                    Workshop_FactoryCode_FactoryCode = DC.Set<Factory>().Where(z0 => z0.FactoryCode == x.FactoryCodeId).Select(y => y.FactoryCode).FirstOrDefault(),
                    Workshop_WorkshopCode = x.WorkshopCode,
                    Workshop_WorkshopName = x.WorkshopName,
                    Workshop_ResponsibleId = x.ResponsibleId,
                    Workshop_Status = x.Status,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class Workshop_View: Workshop
    {
        
        public string Workshop_FactoryCode_FactoryCode { get; set; }
        public string Workshop_WorkshopCode { get; set; }
        public string Workshop_WorkshopName { get; set; }
        public string Workshop_ResponsibleId { get; set; }
        public BaseStatusEnum? Workshop_Status { get; set; }

    }

}